package com.hly.tool.exception;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * @author ：Jack Hao
 * @date ：Created in 2021/7/22 16:05
 * @description：
 */
public class ExceptionUtil
{

    /**
     * 获取异常信息的所有数据
     *
     * @param throwable
     * @return
     */
    public static String getStackTrace(Throwable throwable)
    {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        try
        {
            throwable.printStackTrace(pw);
            return sw.toString();
        } finally
        {
            if (pw != null)
            {
                try
                {
                    pw.close();
                } catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
            if (sw != null)
            {
                try
                {
                    sw.close();
                } catch (Exception e)
                {
                    e.printStackTrace();
                }
            }
        }
    }


}
